package com.igoal.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.igoal.service.UserManagerExt;
import com.igoal.web.model.BaseModel;

@Controller
@RequestMapping("/index.html")
@Secured("ROLE_ANONYMOUS")
public class HomeController extends BaseController {
	@Autowired
	public void setUserManagerExt(UserManagerExt userManagerExt) {
		this.userManagerExt = userManagerExt;
	}
	
	public String getViewPrefix() {
		return BaseControllerDelegate.DEFAULT_VIEW_PREFIX;
	}
	
	@RequestMapping(method=RequestMethod.GET)
	public String showHomePage(ModelMap model, HttpServletRequest request, @RequestParam(required=false, value="step1") Integer step1, 
			@RequestParam(required=false, value="step2") Integer step2){		
		if(isLoginUser()) return "redirect:dashboard.html";
		
		// TODO: remove after newyear campaign ended
//		if(step1 == null && step2 == null){
//			return "redirect:/cp/newyear2011.html";
//		}
		
		return getViewPrefix() + "index";
	}

	public void initTopPage(BaseModel model, HttpServletRequest request) {}

	public void initRightPage(BaseModel model, HttpServletRequest request) {}

	public void initLeftPage(BaseModel model, HttpServletRequest request) {}
}
